export function isString(value) {
	return typeof value === "string"
}
export function isEmpty(val : any) {
	if (typeof val == "boolean") {
		return false
	}
	if (typeof val == "number") {
		return false
	}
	if (val instanceof Array) {
		if (val.length == 0) return true
	} else if (val instanceof Object) {
		if (JSON.stringify(val) === "{}") return true
	} else {
		if (val == "null" || val == null || val == "undefined" || val == undefined || val == "") return true
		if ((val + "").replace(/\s*/g, "") == "") return true
		return false
	}
	return false
}

export function getCurrentColor({ color, max, value } : any) {
	if (isString(color)) {
		return color
	} else {
		const colorArray = color
			.map((item : any, index : number) => {
				if (isString(item)) {
					return {
						color: item,
						value: (index + 1) * (max / color.length)
					}
				}
				return item
			})
			.sort((a : any, b : any) => a.value - b.value)

		for (let i = 0; i < colorArray.length; i++) {
			if (colorArray[i].value >= value) {
				return colorArray[i].color
			}
		}
		return colorArray[colorArray.length - 1].color
	}
}